package com.example.travelservlet.scenery.controller;

import com.example.travelservlet.city.service.CityService;
import com.example.travelservlet.entity.City;
import com.example.travelservlet.entity.Scenery;
import com.example.travelservlet.entity.User;
import com.example.travelservlet.scenery.service.SceneryService;
import com.example.travelservlet.entertainmentLabel.service.EntertainmentLabelService;
import com.example.travelservlet.user.domain.Result;
import com.example.travelservlet.user.exception.BizException;
import com.example.travelservlet.user.service.UserService;
import com.example.travelservlet.userLabel.service.UserLabelService;
import com.example.travelservlet.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author dell
 */
@RestController
@RequestMapping("/scenery")
public class SceneryController {
    @Autowired
    private SceneryService sceneryService;
    @Autowired
    private UserService userService;
    @Autowired
    private CityService cityService;
    @Autowired
    private UserLabelService userLabelService;
    @Autowired
    private EntertainmentLabelService sceneryLabelService;

/**
    @GetMapping("/findScenery/{loginName}")
    public Result<List<Scenery>> findScenery(@PathVariable String loginName, Scenery scenery,
                                             @RequestParam (name = "page",required = false,defaultValue = "1") Integer page,
                                             @RequestParam(name = "size",required = false,defaultValue = "10") Integer size){
        User user = userService.findUserByLoginName(loginName);
        City city = cityService.findCityById(user.getCityId());

        List<String> labels = userLabelService.findLabelIdsByUserId(user.getUserId());
        List<String> sceneryIds = sceneryLabelService.listSceneryIds(labels);


        if (page < 1){
            throw new BizException("[查询所有用户]:当前页码不能小于1");
        }
        Sort.Order ageOrder = Sort.Order.desc("age");
        Sort.Order loginNameOrder = Sort.Order.desc("loginName");
        Sort sort = Sort.by(ageOrder,loginNameOrder);
        Pageable pageable = PageRequest.of(page-1,size,sort);
        Page pageResult = sceneryService.findSceneriesByCityIdAndSceneryIds(city,sceneryIds,pageable);
        return ResultUtil.success(pageResult);
    }

*/

}
